package com.hackerchat.server;

import java.io.*;
import java.net.*;

import com.hackerchat.utils.SCLog;

public class SCClientHandler extends Thread {

	private SCServer server;
	private Socket socket;

	public SCClientHandler(SCServer server, Socket socket) {
		this.server = server;
		this.socket = socket;
		start();
	}

	public void run() {
		try {
			DataInputStream dis = new DataInputStream( this.socket.getInputStream() );
			while( true ) {
				String message = dis.readUTF();
				System.out.println("Sending " + message);
				server.sendToAll(message);
			}
		} catch( EOFException eofe ) {
		} catch( IOException ie ) {

			SCLog.writeErrorMessage( "Unexpected input/output exception" );
		
		} finally {

			server.removeConnection(socket);

		}
	}
}